import * as monaco from 'monaco-editor'
export const languageID = 'myLanguage'
import * as MyLanguage from './my_language.contribution.js'
const innerSuggestions = [
    /**   * 内置函数   */
    {
        label: 'hello(text:string)',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: 'hello(${1:text})',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: '将字符串转型日期格式化成日期对象，参数只会取年月日部分,返回日期型对象'
    },
     {
        label: '_COS(val:number)',
        kind: monaco.languages.CompletionItemKind.Function,
        insertText: '_COS(${1:val})',
        insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
        detail: '求指定角度的余弦值'
    },
    {
        label: 'Async Block',
        kind: monaco.languages.CompletionItemKind.Snippet,
        documentation: 'Add an async block',
        insertText: [
            '(async () => {',
            '\t',
            '})()'].join('\n')
    },
    {
        label: 'for: Array',
        kind: monaco.languages.CompletionItemKind.Snippet,
        documentation: 'Iterate over an Array',
        detail: 'for 循环',
        insertText: [
            'for(let i=0; i < arr.length; i++){',
            '\tlet elem = arr[i];',
            '',
            '}'].join('\n')
    }, {
        label: 'startTime',
        kind: monaco.languages.CompletionItemKind.Variable,
        insertText: 'startTime',
        detail: '开始时间'
    },
    {
        label: 'endTime',
        kind: monaco.languages.CompletionItemKind.Variable,
        insertText: 'endTime',
        detail: '结束时间'
    }
]

const textSuggestions = (items) => {
    return items.map((element => ({
            label: element,
            kind: monaco.languages.CompletionItemKind.Text,
            insertText: element,
            insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
            detail: element
    }))) 
}

export const suggestions = () => {
    let result = []
    result = result.concat(innerSuggestions)
    result = result.concat(textSuggestions(MyLanguage.language.operators))
    result = result.concat(textSuggestions(MyLanguage.language.builtinFunctions))
    result = result.concat(textSuggestions(MyLanguage.language.keywords))
    return result
}